package com.cisetech.vo;

import java.util.ArrayList;
import java.util.List;


public class Page<T> {
	private int pageNo; // 当前页码
	private int pageSize; // 页面大小，设置为“-1”表示不进行分页（分页无效）
	
	private long count;// 总记录数，设置为“-1”表示不查询总数
	private long countpage;// 总记录页数
	
	private long calculationPge;// 计算从多少条开始，开始条数
	
	private int first;// 首页索引
	private int last;// 尾页索引
	
	
	
	public long getCalculationPge() {
		return calculationPge;
	}
	public void setCalculationPge(long calculationPge) {
		this.calculationPge = calculationPge;
	}
	public long getCountpage() {
		return countpage;
	}
	public void setCountpage(long countpage) {
		this.countpage = countpage;
	}
	private List<T> list = new ArrayList<T>();
	
	private String html;
	
	public int getPageNo() {
		return pageNo;
	}
	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public long getCount() {
		return count;
	}
	public void setCount(long count) {
		this.count = count;
	}
	public int getFirst() {
		return first;
	}
	public void setFirst(int first) {
		this.first = first;
	}
	public int getLast() {
		return last;
	}
	public void setLast(int last) {
		this.last = last;
	}
	public List<T> getList() {
		return list;
	}
	public void setList(List<T> list) {
		this.list = list;
	}
	public String getHtml() {
		return html;
	}
	public void setHtml(String html) {
		this.html = html;
	}
	public void Pagehtml(int pageNo, int pageSize, long count,
			List<T> list) {
		this.pageNo = pageNo;
		this.pageSize = pageSize;
		this.count = count;
		this.list = list;
		if(count%pageSize>0){
			this.countpage = count/pageSize+1;
		}else{
			this.countpage = count/pageSize;
		}
		if(countpage>=3){
			this.html = getHtml2(countpage, pageNo, pageSize);
		}else{
			this.html = getHtml(countpage, pageNo, pageSize);
		}
	}
	//不足三页
	public String getHtml(Long countpage,int pageNo,int pageSize){
		String ht="";
		if(countpage==1){//总页数等于1的时候
			ht = "<tr id='paget'>"+
			        "<td colspan='8'>"+
			        "<div class='pagelist'>"+
			        "<span class='current'>1</span>"+
			        "<a href='javascript:void(0)' >共"+countpage+"页</a>"+
			        "</div></td>"+
			      "</tr>";
		}else if(countpage==2){//总页数等于2的时候
			if(pageNo==1){//当前页为1的时候
				ht = "<tr id='paget'>"+
				        "<td colspan='8'>"+
				        "<div class='pagelist'>"+
				        "<a href='javascript:void(0)'>上一页</a> "+
				        "<span class='current'>1</span>"+
				        "<a href='javascript:void(0)' onclick='page(2,"+pageSize+")'>2</a>"+
				        "<a href='javascript:void(0)' onclick='page(2,"+pageSize+")'>下一页</a>"+
				        "<a href='javascript:void(0)' id='searchInput' onclick='page(0,"+pageSize+",\"search\")'>尾页</a> "+
				        "<a href='javascript:void(0)'><input id='last' type='text' style='width:50px;''></a>"+
				        "<a href='javascript:void(0)' onclick='pageGo("+pageSize+")'>GO!</a>"+
				        "<a href='javascript:void(0)' >共"+countpage+"页</a>"+
				        "</div></td>"+
				      "</tr>";
			}else{//当前页为2的时候
				ht = "<tr id='paget'>"+
				        "<td colspan='8'>"+
				        "<div class='pagelist'>"+
				        "<a href='javascript:void(0)' onclick='page(1,"+pageSize+")'>上一页</a> "+
				        "<a href='javascript:void(0)' onclick='page(1,"+pageSize+")'>1</a>"+
				        "<span class='current'>2</span>"+
				        "<a href='javascript:void(0)'>下一页</a>"+
				        "<a href='javascript:void(0)' id='searchInput' onclick='page(0,"+pageSize+",\"search\")'>尾页</a> "+
				        "<a href='javascript:void(0)'><input id='last' type='text' style='width:50px;''></a>"+
				        "<a href='javascript:void(0)' onclick='pageGo("+pageSize+")'>GO!</a>"+
				        "<a href='javascript:void(0)' >共"+countpage+"页</a>"+
				        "</div></td>"+
				      "</tr>";
			}
			
		}
		return ht;
	}
	//大于3页的情况
	public String getHtml2(Long countpage,int pageNo,int pageSize){
		String ht="";
		if(pageNo==1){//当前页为1的时候
			ht = "<tr id='paget'>"+
			        "<td colspan='8'>"+
			        "<div class='pagelist'>"+
			        "<a href='javascript:void(0)'>上一页</a> "+
			        "<span class='current'>1</span>"+
			        "<a href='javascript:void(0)' class='current' onclick='page(2,"+pageSize+")'>2</a>"+
			        "<a href='javascript:void(0)' onclick='page(3,"+pageSize+")'>3</a>"+
			        "<a href='javascript:void(0)' onclick='page(2,"+pageSize+")'>下一页</a>"+
			        "<a href='javascript:void(0)' id='searchInput' onclick='page(0,"+pageSize+",\"search\")'>尾页</a> "+
			        "<a href='javascript:void(0)'><input id='last' type='text' style='width:50px;''></a>"+
			        "<a href='javascript:void(0)' onclick='pageGo("+pageSize+")'>GO!</a>"+
			        "<a href='javascript:void(0)' >共"+countpage+"页</a>"+
			        "</div></td>"+
			      "</tr>";
		}else if(countpage == pageNo){//当前页为最后一页的时候
			ht = "<tr id='paget'>"+
			        "<td colspan='8'>"+
			        "<div class='pagelist'>"+
			        "<a href='javascript:void(0)' onclick='page("+(pageNo-1)+","+pageSize+")'>上一页</a> "+
			        "<a href='javascript:void(0)' onclick='page("+(pageNo-2)+","+pageSize+")'>"+(pageNo-2)+"</a>"+
			        "<a href='javascript:void(0)' onclick='page("+(pageNo-1)+","+pageSize+")'>"+(pageNo-1)+"</a>"+
			        "<span class='current'>"+pageNo+"</span>"+
			        "<a href='javascript:void(0)'>下一页</a>"+
			        "<a href='javascript:void(0)' id='searchInput' onclick='page(0,"+pageSize+",\"search\")'>尾页</a> "+
			        "<a href='javascript:void(0)'><input id='last' type='text' style='width:50px;''></a>"+
			        "<a href='javascript:void(0)' onclick='pageGo("+pageSize+")'>GO!</a>"+
			        "<a href='javascript:void(0)' >共"+countpage+"页</a>"+
			        "</div></td>"+
			      "</tr>";
		}else{
			ht = "<tr id='paget'>"+
			        "<td colspan='8'>"+
			        "<div class='pagelist'>"+
			        "<a href='javascript:void(0)' onclick='page("+(pageNo-1)+","+pageSize+")'>上一页</a> "+
			        "<a href='javascript:void(0)' onclick='page("+(pageNo-1)+","+pageSize+")'>"+(pageNo-1)+"</a>"+
			        "<span class='current'>"+pageNo+"</span>"+
			        "<a href='javascript:void(0)' onclick='page("+(pageNo+1)+","+pageSize+")'>"+(pageNo+1)+"</a>"+
			        "<a href='javascript:void(0)' onclick='page("+(pageNo+1)+","+pageSize+")'>下一页</a>"+
			        "<a href='javascript:void(0)' id='searchInput' onclick='page(0,"+pageSize+",\"search\")'>尾页</a> "+
			        "<a href='javascript:void(0)'><input id='last' type='text' style='width:50px;''></a>"+
			        "<a href='javascript:void(0)' onclick='pageGo("+pageSize+")'>GO!</a>"+
			        "<a href='javascript:void(0)' >共"+countpage+"页</a>"+
			        "</div></td>"+
			      "</tr>";
		}
		return ht;
	}
}
